
import unittest

from api.ihrm_emp_curd import IhrmEmpCurd
from common.get_token import get_header
from common.ihrm_login_duanyan import assert_util
from common.mysql_util import DB
from common.ihrm_login_read import read_login_data
from config import token
from config import tel
from parameterized import parameterized

class TestEmpAdd(unittest.TestCase):
    #类夹具_获得hesder
    @classmethod
    def setUpClass(cls) -> None:
        cls.header=get_header()
     # 调用方法前夹具
    def setUp(self) -> None:
        delete_sql = f"delete from bs_user where mobile={tel}"
        DB.idu_sql(delete_sql)

    # 调用方法后夹具
    def tearDown(self) -> None:
        delete_sql = f"delete from bs_user where mobile={tel}"
        DB.idu_sql(delete_sql)

    #file_path = BASEDTR + "\data\"

    data = read_login_data("ihrm_add_emp.json")

    # 定义通用测试方法
    @parameterized.expand(data)
    def test_common(self, desc, req_body, status_code,success,code,msg):
        # 组织数据
        #hader = {"Content-Type": "application/json","Authorization": token}
        header=get_header()
        # 调用封装好的接口发，发送请求
        resp1 = IhrmEmpCurd.add_emp(self.header, req_body)

        # 断言
        assert_util(self,resp1, status_code, bool(success), code,msg)
        #添加员工： {'success': False, 'code': 20002, 'message': '新增员工失败', 'data': None}
        #添加员工： {'success': True, 'code': 10000, 'message': '操作成功！', 'data'xxx}
#

    # # 必须参数
    # def test01_bixuan(self):
    #     # 组织数据
    #     hader1 = {"Content-Type": "application/json","Authorization": token}
    #     body1 = {"username": "alex05", "mobile": "13065312315", "workNumber": "1234"}
    #
    #     # 调用封装好的接口发，发送请求
    #     resp1 = IhrmEmpCurd.add_emp(hader1, body1)
    #
    #     # 断言
    #     assert_util(self,resp1, 200, True, 10000,"操作成功！" )
    #     #添加员工： {'success': False, 'code': 20002, 'message': '新增员工失败', 'data': None}
    #     #添加员工： {'success': True, 'code': 10000, 'message': '操作成功！', 'data'xxx}
    #
    # # 参数组合
    # def test02_zuhecanshu(self):
    #     # 组织数据
    #     hader2 = {"Content-Type": "application/json",
    #               "Authorization": token}
    #     body2 = {"username": "jack003","mobile": "13065312315","workNumber": "1234","timeOfEntry": "2022-06-01"}
    #
    #     # 调用封装好的接口发，发送请求
    #     resp2 = IhrmEmpCurd.add_emp(hader2, body2)
    #
    #     # 断言
    #     assert_util(self,resp2, 200, True, 10000,"操作成功！")
    #     #{'success': True, 'code': 10000, 'message': '操作成功！', 'data':

